<?php

class UserIdentity extends CUserIdentity
{
    /**
    * User's attributes
    * @var array
    */
    private $_id;
    private $_model;
 
    public function authenticate()
    {
        $this->errorCode=self::ERROR_PASSWORD_INVALID;
        $account = Account::model()->findByAttributes(array('email'=>CHtml::encode($this->username)));

		if($account === null)
		{
			$this->errorCode=self::ERROR_USERNAME_INVALID;
			return !$this->errorCode;
		}
		
		// original : $user->password === md5($user->salt.$this->password)
		if ($account->password !== md5($this->password)) {
			$this->errorCode=self::ERROR_PASSWORD_INVALID;
			return !$this->errorCode;
		}
		
		$this->errorCode=self::ERROR_NONE;
		$this->_id = $account->uid;
		$this->_model = $account;
        return !$this->errorCode;
    }
 
    public function getId()
    {
    	return $this->_id;
    }
    
    public function getModel()
    {
    	return $this->_model;
    }
}